
import numpy as np
class QuadraticLoss:
    def __init__(self):
        pass
    
    def forward(self,x,label):
        self.x=x
        self.label=np.zeros_like(x)
        for a,b in zip(self.label,label):
            a[b-1]=1
        self.loss=np.sum(np.square(self.label-x))/self.x.shape[0]/2
        return self.loss  # 26*1

    def backward(self):
        self.dx=(self.x-self.label)/self.x.shape[0]
        return self.dx